
import Dialog from '@vant/weapp/dialog/dialog';
Page({
  data: {
    list: {},
    id: 1,//房间id
    //房屋列表
    building: '',//楼栋
    gender: '',//性别
    mobile: '',//手机号
    name: '',//姓名
    point: '',//小区信息
    room: '',//小区房间信息
    status: '',//房间状态 审核状态1审核中2审核成功3审核失败
  },

  //默认展示列表
  onLoad() {
    this.getList()
  },


  async getList() {
    const res = await wx.http.get('/room')
    this.setData({ list: res })

    console.log('获取列表2', res);
  },

  deleteHouse(ev) {
    console.log('删除', ev.mark.id);
    this.id = ev.mark.id
    const { position, instance } = ev.detail
    if (position === 'right') {
      // 显示 Dialog 对话框
      Dialog.confirm({
        title: '提示',
        message: '是否删除已绑定房屋？',
      })
        .then(async () => {
          // 确认
          await wx.http.delete(`/room/${ev.mark.id}`)
          this.getList()
        })
        .catch(() => {
          // on cancel
        });

      // swiper-cell 滑块关闭
      instance.close()
    }
  },

  goDetail(ev) {
    // console.log('详情', ev.mark.id);
    wx.navigateTo({
      url: `/house_pkg/pages/detail/index?id=${ev.mark.id}`,
    })
  },

  addHouse() {
    wx.navigateTo({
      url: '/house_pkg/pages/locate/index',
    })
  },
})
